package teaMainFrame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rORM.core.Query;
import com.rORM.core.QueryFactory;

import database.Teacher;
import login.login;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;

public class TeaMainFrame extends JFrame {
	private JPanel contentPane;
	private Teacher t;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TeaMainFrame frame = new TeaMainFrame(16401);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TeaMainFrame(int id) {
		
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(449, 313);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		t = loadTeaInfo(id);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu create = new JMenu("新建");
		menuBar.add(create);
		
		JMenuItem lessonTable = new JMenuItem("课表");
		lessonTable.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new CreateTeacherTable(t.getTeacherID());
			}
		});
		create.add(lessonTable);
		
		JMenuItem menuItem_2 = new JMenuItem("成绩表");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ScoreTable();
			}
		});
		create.add(menuItem_2);
		
		JMenuItem course = new JMenuItem("课程");
		course.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new CreateCourse();
			}
		});
	
		create.add(course);
		
		JMenu menu = new JMenu("查询或修改");
		menuBar.add(menu);
		
		JMenuItem menuItem = new JMenuItem("课表");
		menu.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("学生信息");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SelectStuInfoList();
			}
		});
		menu.add(menuItem_1);
		
		JMenuItem menuItem_3 = new JMenuItem("学生成绩");
		menuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SelectStuGrades();
			}
		});
		menu.add(menuItem_3);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("欢迎使用学生管理系统");
		lblNewLabel.setFont(new Font("Dialog", Font.PLAIN, 17));
		lblNewLabel.setBounds(188, 103, 202, 43);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("尊敬的");
		label.setFont(new Font("Dialog", Font.PLAIN, 17));
		label.setBounds(29, 103, 63, 43);
		contentPane.add(label);
		
		JLabel name = new JLabel(t.getName());
		name.setForeground(Color.RED);
		name.setFont(new Font("Lucida Grande", Font.PLAIN, 21));
		name.setBounds(84, 103, 105, 43);
		contentPane.add(name);
		
		JButton button = new JButton("退出登录");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new login();
				setVisible(false);
			}
		});
		button.setBounds(335, 211, 90, 29);
		contentPane.add(button);
	}
	public Teacher loadTeaInfo(int id){
		Query q = QueryFactory.createQuery();
		Teacher t1 = (Teacher)q.queryUniqueRow("select * from teacher where teacherID = ?",Teacher.class,new Object[]{id});
		return t1;
	}
}
